<template>
	<view class="content">
		<u-navbar bgColor="transparent" titleStyle="color:#fff" title="我的求购" leftIconColor="#fff" :autoBack="true"
			:placeholder="false">
		</u-navbar>
		<view class="content-box">
			<view class="trade" v-for="(item,index) in list" :key="index">
				<view class="trade-head">
					<view class="trade-box">
						<image :src="item.avatar" mode=""></image>
						<view class="trade-right">
							{{item.user}}
						</view>
					</view>
					<view class="tisp"> 挂单中</view>
				</view>
				<view class="info">
					<view class="info-item">
						<view class="info-num">
							<text>{{item.num}}</text>
						</view>
						<view class="info-text">
							数量(云矿石)
						</view>
					</view>
					<view class="info-item">
						<view class="info-num">
							<text>{{item.price}}</text>
						</view>
						<view class="info-text">
							单价(CYN)
						</view>
					</view>
					<view class="info-item">
						<view class="info-num">
							<text>{{item.total_price}}</text>
						</view>
						<view class="info-text">
							总价(CYN)
						</view>
					</view>
				</view>
				<view class="btn">
					<u-button color="linear-gradient( 90deg, #C8F673 0%, #98F083 100%)"
						style="color: #000;border-radius: 30rpx;" @click="cancel(item.id)" type="primary"
						text="取消挂单"></u-button>
				</view>
			</view>
			<u-loadmore :status="morestatus" :margin-top="20" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				morestatus: "loadmore",
				page: 1,
			}
		},
		onShow() {
			this.postlist()
		},
		onReachBottom() {
			this.morestatus = "loading"
			this.page++
			this.postlist()
		},
		methods: {
			cancel(id) {
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否取消此订单！',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							app.$Request({
								method: 'POST',
								url: '/api/exchange/unpublish_qiu',
								data: {
									id: id
								}
							}).then(res => {
								uni.hideLoading()
								if (res.code == 1) {
									uni.showToast({
										title: '取消成功！',
										icon: 'none'
									})
									app.page = 1
									app.postlist()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			postlist() {
				let params = {
					type:3,
					page: this.page,
					status: 1
				}
				this.$Request({
					method: 'POST',
					url: '/api/exchange/myrelease',
					data: params
				}).then(res => {
					if (res.code == 1) {
						if (res.data.list.length < 10) {
							this.morestatus = "nomore"
						}
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list];
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})

			},
		}
	}
</script>
<style>
	page {
		background: #17191A;
	}
</style>
<style lang="scss" scoped>
	.content-box {
		padding: 120rpx 30rpx 30rpx 30rpx;
		min-height: 100vh;
		background-image: url('../../../static/my/my-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 568rpx;

		.trade {
			margin-top: 30rpx;
			padding: 30rpx;
			background: linear-gradient(134deg, rgba(255, 227, 211, 0.06) 0%, rgba(67, 130, 84, 0.26) 100%);
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			border: 4rpx solid rgba(108, 233, 137, 0.12);
			color: #fff;
			position: relative;

			.trade-head {
				display: flex;
				justify-content: space-between;
				align-items: center;
				position: relative;

				.tisp {
					top:0;
					right: 0;
					position: absolute;
					font-size: 26rpx;
				}

				.trade-box {
					display: flex;
					align-items: center;

					.trade-right {
						font-size: 32rpx;
						font-weight: 600;
					}
				}

				image {
					width: 90rpx;
					height: 90rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}
			}

			.btn {
				margin-top: 30rpx;
			}

			.info {
				display: flex;
				justify-content: space-around;
				text-align: center;
				margin: 20rpx 0;

				.info-item {
					width: 33%;

					.info-num {
						color: #A1FFA9;

						text {
							font-size: 30rpx;
							font-weight: 600;
						}
					}

					.info-text {
						font-size: 24rpx;
						color: #999;
						margin-top: 10rpx;
					}
				}
			}
		}
	}
</style>